package com.haoting.blogservice.controller.front;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.haoting.blogservice.entity.vo.BlogIndexVo;
import com.haoting.blogservice.entity.vo.BlogInfoVo;
import com.haoting.blogservice.entity.vo.FrontBlogQuery;
import com.haoting.blogservice.service.BlogService;
import com.haoting.commonutils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/blogservice/blogfront")
//@CrossOrigin
public class BlogFrontController {

        @Autowired
        BlogService blogService;

        @PostMapping("getBlogFrontList/{page}/{limit}")
        public CommonResult getBlogFrontList(@PathVariable long page, @PathVariable long limit,
                                             @RequestBody(required = false) FrontBlogQuery frontBlogQuery){
                Page<BlogIndexVo> blogPage = new Page<>(page,limit);
                blogService.getblogFront(blogPage,frontBlogQuery);
                long total = blogPage.getTotal();
                List<BlogIndexVo> records = blogPage.getRecords();
                return CommonResult.ok().data("total",total).data("rows",records);

        }

        @PostMapping("addlook/{blogId}")
        public CommonResult addlook(@PathVariable String blogId){
                blogService.addlook(blogId);
                return CommonResult.ok();
        }
}
